﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Modele;

namespace Guitar.Vues
{
    /// <summary>
    /// Logique d'interaction pour VueNote.xaml
    /// </summary>
    public partial class VueSilence : Canvas
    {

        public Note note;
        private bool _IsSelected = false;

        public bool IsSelected{

            get { return _IsSelected; }
            set
            {
                _IsSelected = value; if (value)
                {

                    FondNote.Fill = (Brush)FindResource("selected");
                   
                    FondNote.Visibility = Visibility.Visible;
                }
                else { FondNote.Visibility = Visibility.Hidden; }
            }


        }



        /* Permet d'instancier une note sur une portée */
        public VueSilence()
        {
            InitializeComponent();
        }

        public VueSilence(Note n)
        {
            InitializeComponent();
            note = n;
            update();
        }
       
        private void Rectangle_MouseEnter(object sender, MouseEventArgs e)
        {
            FondNote.Visibility = Visibility.Visible;
            if (!IsSelected)
            {
                FondNote.Fill = (Brush)FindResource("over");
         
            }

        }

        private void Rectangle_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!IsSelected)
            {
                FondNote.Visibility = Visibility.Hidden;
            }

        }

        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {

            if (IsSelected)
            {
                IsSelected = false;
            }
            else
            {
                IsSelected = true;
            }

            App.lecteur.Lire(note);
           
        }

        /* Met à jour l'apparence de la note en fonction de ses caractéristiques */
        public void update()
        {
            if (note.pointure ==Note.Pointure.Pointe)
            {
                point.Visibility=Visibility.Visible;
            }else{
                 point.Visibility=Visibility.Hidden;
            }

           

            switch (note.rythme)
            {

                case Note.TypeRytmique.Pause:
                     Canvas.SetLeft(Silence, 41);
                    Canvas.SetTop(Silence, 4);
                    ; break;
                    
                case Note.TypeRytmique.DemiPause:
                    Canvas.SetLeft(Silence, 41);
                    Canvas.SetTop(Silence, 6);
                    ; break;
                case Note.TypeRytmique.SeiziemeSoupir:
                            
                ; break;


              // ...

            }

                     
            String[] noteName = note.ToString(App.option.LangueNotationMusicale);
            Tool.Content = "\nRythme : " + noteName[3];
        }


        public void SetAllInvisible()
        {
            Silence.Visibility = Visibility.Hidden;
            point.Visibility = Visibility.Hidden;
        }
    }



}
